package net.cyl.component;

import lombok.extern.slf4j.Slf4j;
import net.cyl.emums.ProductOrderPayTypeEnum;
import net.cyl.vo.PayInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class PayFactory {


    @Autowired
    private AliPayStrategy aliPayStrategy;

    @Autowired
    private WechatPayStrategy wechatPayStrategy;

    // 根据支付类型，调用对应的支付策略
    public String pay(PayInfoVO payInfoVO){
        String payType = payInfoVO.getPayType();
        if(ProductOrderPayTypeEnum.ALIPAY.name().equals(payType)){

        }
        else if(ProductOrderPayTypeEnum.WEICHATPAY.name().equals(payType)){
            PayStrategyContext  payStrategyContext = new PayStrategyContext(wechatPayStrategy);
            return payStrategyContext.executeUnifiedOrder(payInfoVO);
        }
        return "";
    }


    // 根据支付类型，调用对应的支付策略
    public String closeOrder(PayInfoVO payInfoVO){
        String payType = payInfoVO.getPayType();
        if(ProductOrderPayTypeEnum.ALIPAY.name().equals(payType)){
            PayStrategyContext  payStrategyContext = new PayStrategyContext(aliPayStrategy);
            return payStrategyContext.executeCloseOrder(payInfoVO);
        }

        else if(ProductOrderPayTypeEnum.WEICHATPAY.name().equals(payType)){
            PayStrategyContext  payStrategyContext = new PayStrategyContext(wechatPayStrategy);
            return payStrategyContext.executeCloseOrder(payInfoVO);
        }
        return "";
    }


    // 根据支付类型，调用对应的支付策略
    public String queryPayStatus(PayInfoVO payInfoVO){
        String payType = payInfoVO.getPayType();
        if(ProductOrderPayTypeEnum.ALIPAY.name().equals(payType)){
            PayStrategyContext  payStrategyContext = new PayStrategyContext(aliPayStrategy);
            return payStrategyContext.executeQueryPayStatus(payInfoVO);
        }

        else if(ProductOrderPayTypeEnum.WEICHATPAY.name().equals(payType)){
            PayStrategyContext  payStrategyContext = new PayStrategyContext(wechatPayStrategy);
            return payStrategyContext.executeQueryPayStatus(payInfoVO);
        }
        return "";
    }

    // 根据支付类型，调用对应的支付策略
    public String refund(PayInfoVO payInfoVO){
        String payType = payInfoVO.getPayType();
        if(ProductOrderPayTypeEnum.ALIPAY.name().equals(payType)){
            PayStrategyContext  payStrategyContext = new PayStrategyContext(aliPayStrategy);
            return payStrategyContext. executeRefund(payInfoVO);
        }

        else if(ProductOrderPayTypeEnum.WEICHATPAY.name().equals(payType)){
            PayStrategyContext  payStrategyContext = new PayStrategyContext(wechatPayStrategy);
            return payStrategyContext. executeRefund(payInfoVO);
        }
        return "";
    }
}
